﻿using System.Threading.Tasks;

namespace Sidvall.Net
{
    public class ProxyStrategyManager
    {
        #region Public Members

        public Sidvall.Net.IProxyStrategy ProxyStrategy { get; set; }

        #region Proxy

        public ProxySettings Proxy
        {
            get
            {
                return this.ProxyStrategy?.Proxy;
            }
        }

        #endregion

        #region LoadProxy

        public void LoadProxy(string content)
        {
            if (this.ProxyStrategy != null)
                this.ProxyStrategy.LoadProxy(content);
        }
        public void LoadProxy(ProxySettings proxy)
        {
            if (this.ProxyStrategy != null)
                this.ProxyStrategy.LoadProxy(proxy);
        }

        #endregion
        #region LoadProxyAsync

        public async Task LoadProxyAsync(bool refresh)
        {
            if (this.ProxyStrategy != null)
                await this.ProxyStrategy.LoadProxyAsync(refresh).ConfigureAwait(false);
        }

        #endregion
        #region SaveProxyAsync

        public async Task SaveProxyAsync()
        {
            if (this.ProxyStrategy != null)
                await this.ProxyStrategy.SaveProxyAsync().ConfigureAwait(false);
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return "ProxyStrategyManager - Sidvall.Net.IProxyStrategy";
        }

        #endregion

        #endregion
        #region Constructors

        public ProxyStrategyManager(Sidvall.Net.IProxyStrategy proxyStrategy)
        {
            this.ProxyStrategy = proxyStrategy;
        }

        #endregion
    }
}
